/**
 * Copyright (C) 2014 xspace app Project.
 */

package cn.xspace.module.other.http.impl;

import com.xspace.android.xafcommon.been.UserInfoBean;
import com.xspace.android.xafcommon.network.NetConstant;
import com.xspace.android.xafcommon.network.message.AResponseMsg;
import com.xspace.android.xafcommon.network.message.SendRequestListener;
import cn.xspace.library.util.MyInfoUtil;

import android.content.Context;
import android.widget.Toast;
import cn.xspace.module.other.application.MyApplication;
import cn.xspace.module.other.http.NetControl;
import cn.xspace.module.other.http.intface.IQueryUserInfo;
import cn.xspace.module.other.http.resp.QueryUserInfoResp;
import cn.xspace.module.other.util.RProxy;

/**
 * @ClassName: QueryUserInfoImpl
 * @author:mawen
 * @Date：2014-2-25
 * @version V1.0.0
 * @Description: TODO
 */
public class QueryUserInfoImpl implements SendRequestListener, IQueryUserInfo {
	private NetControl netControl;
	private Context mContext;
	private IQueryUserInfoRequest mCallBack;

	/**
	 * @Description: TODO
	 * @param
	 * @return
	 * @throws
	 */
	public QueryUserInfoImpl(Context context) {
		this.mContext = context;
		netControl = new NetControl(this);
	}

	@Deprecated
	@Override
	public void queryUserInfo(String accountID, String update_time,
			IQueryUserInfoRequest mCallBack) {
		this.mCallBack = mCallBack;
		String deptid = MyInfoUtil.getAppInfo(MyApplication.get()).app_deptid;
		String appid= MyInfoUtil.getAppInfo(MyApplication.get()).app_id;
		netControl.sendQueryUserInfoReq(accountID,deptid,appid);
	}

	/*
	 * <p>Title: requestResult</p> <p>Description: </p>
	 * 
	 * @param result
	 * 
	 * @param object
	 * 
	 * @see com.xspace.android.xafcommon.network.message.SendRequestListener#
	 * requestResult(int,
	 * com.xspace.android.xafcommon.network.message.AResponseMsg)
	 */
	@Override
	public void requestResult(int result, AResponseMsg object) {
		if (object.msgType.equals(NetControl.MSGTYPE_QUERY_USERINFO)) {
			
			if (result == NetConstant.TaskStatus.SUCCESS) {
				QueryUserInfoResp resp = (QueryUserInfoResp) object;
				if (resp.userInfoBean != null) {// 获取成功
					UserInfoBean userInfo = (UserInfoBean) resp.userInfoBean;
					mCallBack.onResult(userInfo);
//					MyInfoUtil.setUserInfo(userInfo);
				}else{
					mCallBack.onResult(null);
				}
			} else {

				Toast.makeText(mContext, RProxy.network_fail, Toast.LENGTH_LONG)
						.show();
				
				mCallBack.onResult(null);
			}
		}
	}

	@Override
	public void offline(String msgType) {
		Toast.makeText(mContext, RProxy.network_fail, Toast.LENGTH_SHORT)
				.show();
		mCallBack.onResult(null);
	}

	public interface IQueryUserInfoRequest {
		public void onResult(UserInfoBean returnRes);
	}
}
